<%-- 
    Document   : header
    Created on : Mar 17, 2012, 10:55:30 AM
    Author     : Doodles
--%>

<%@page import="java.util.ArrayList"%>
<%@page import="com.mfi.models.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Cache-Control", "no-store");
    response.setDateHeader("Expires", 0);
    response.setHeader("Pragma", "no-cache");
%>
<%!    Customer customer;
    Category category;
    Product product;
    Address address;
    Size size;
    Transaction transaction;
    ArrayList<Category> categories;
    ArrayList<Product> products;
    ArrayList<Customer> customers;
    ArrayList<Address> addresses;
    ArrayList<Size> sizes;
    ArrayList<Transaction> transactions;
    ArrayList<OrderLog> order_log;
%>
<%
    customer = null;
    category = null;
    product = null;
    categories = null;
    products = null;
    customers = null;
    addresses = null;
    address = null;
    sizes = null;
    size = null;
    transaction = null;
    transactions = null;
    order_log = null;

    if (request.getSession().getAttribute("account") != null) {
        customer = (Customer) request.getSession().getAttribute("account");
    }
    if (request.getAttribute("categories") != null) {
        categories = (ArrayList) request.getAttribute("categories");
    }
    if (request.getAttribute("products") != null) {
        products = (ArrayList) request.getAttribute("products");
    }
    if (request.getAttribute("accounts") != null) {
        customers = (ArrayList) request.getAttribute("accounts");
    }
    if (request.getAttribute("category") != null) {
        category = (Category) request.getAttribute("category");
    }
    if (request.getAttribute("product") != null) {
        product = (Product) request.getAttribute("product");
    }
    if (request.getAttribute("addresses") != null) {
        addresses = (ArrayList) request.getAttribute("addresses");
    }
    if (request.getAttribute("address") != null) {
        address = (Address) request.getAttribute("address");
    }
    if (request.getAttribute("size") != null) {
        size = (Size) request.getAttribute("size");
    }
    if (request.getAttribute("sizes") != null) {
        sizes = (ArrayList) request.getAttribute("sizes");
    }
    if (request.getAttribute("transaction") != null) {
        transaction = (Transaction) request.getAttribute("transaction");
    }
    if (request.getAttribute("transactions") != null) {
        transactions = (ArrayList) request.getAttribute("transactions");
    }
    if (request.getAttribute("order_log") != null) {
        order_log = (ArrayList) request.getAttribute("order_log");
    }
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Hotbite : <%= request.getAttribute("title")%></title>
        <link type="text/css" href="/css/ui-lightness/jquery-ui-1.8.17.custom.css" rel="stylesheet" media="screen" />	
        <link type="text/css" href="/css/validator.css" rel="stylesheet" />	
        <link type="text/css" href="/css/styles.css" rel="stylesheet" />
        <script type="text/javascript" src="/js/jquery-1.7.1.min.js"></script>
        <script type="text/javascript" src="/js/jquery-ui-1.8.17.custom.min.js"></script>
        <script type="text/javascript" src="/js/jquery.validate.js"></script>
        <script type="text/javascript" src="/js/jquery.bxSlider.min.js"></script>
        <script type="text/javascript">
            
            $(function(){
                
                //$('#slider').bxSlider({
                //    displaySlideQty: 2,
                //    moveSlideQty: 2,
                //    infiniteLoop: true,
                //    easing: "easeOutElastic",
                //    speed: 1500,
                //    control: false
                //});
                
                var slider = $('#slider').bxSlider({
                    displaySlideQty: 2,
                    moveSlideQty: 1,
                    easing: "easeOutBack",
                    controls: false,
                    speed: 1000,
                    infiniteLoop: true
                });
                
                
                $('.order-prev').click(function(){
                    slider.goToPreviousSlide();
                    return false;
                });

                $('.order-next').click(function(){
                    slider.goToNextSlide();
                    return false;
                });

                // Datepicker
                $('.birthdate').datepicker({
                    showOn: "button",
                    buttonImage: "/images/calendar.gif",
                    buttonImageOnly: true,
                    inline: true,
                    dateFormat: 'yy-mm-dd',
                    changeYear: true,
                    changeMonth: true,
                    autoSize: true,
                    yearRange: '1950:2012'
                });
                        
                $('.register-form').attr('autocomplete','off');
                
                var hidden = true;
                $('.login-btn').click(function() {
                    if (hidden) {
                        $('.login-area').slideDown(500);
                        $('.login-btn').html('Hide');
                        hidden = false;
                    }
                    else {
                        $('.login-area').stop(false, false).slideUp(200);
                        $('.login-btn').html('Account');
                        hidden = true;
                    }
                });
                
                $('.login-area ul li').hover(function() {
                    $(this).animate({'background-color':'#EEE'}, {queue:false, duration:250});
                }, function() {
                    $(this).animate({'background-color':'#FFF'}, {queue:false, duration:400});
                });
                
                $('form[name=login-form]').submit(function() {
                    $('p.error').slideUp();
                    $.post('/login', {
                        username: $('[name=username]').val(),
                        password: $('[name=password]').val()
                    }, function(data) {
                        if (data.success) {
                            location.href=data.redirect;
                        } else {
                            $('p.error').html(data.error).slideDown();
                        }
                    }, 'json');
                   
                    return false;
                   
                });
                
                $('.cart').load('/template/cart.jsp');
                
                $('.login-link').click(function() {
                    $('.login-area').slideDown(500);
                    $('.login-btn').html('Hide');
                    hidden = false;
                    
                    $(this).hide();
                
                    return false;
                });
                
                
                //mimich
                $('.displayAddress_'+$('.address').val()).show();
                
                $('.address').change(function() {
                     
                    //alert('Handler for .change() called.');
                    var add = $(this).val();
                    $('[class^=displayAddress_]').each(function(){
                     
                        $(this).hide();
                        
                    });
                    $('.displayAddress_'+ add).show();
                });     
                 
                 
                 
                $('.finish_btn').click(function() {
                    $.post('/order/checkout/finish', {
                        address: $('.address').val()
                    }, function(data) {
                        if (data.success) {
                            location.href = "/main";
                        } else {
                            location.href = "/order/checkout/summary";
                        }
                    }, 'json');
                });
                
            });
                
                
                
            function reload() {
                location.href=location.href;
            }
                
        </script>
    </head>
    <body>
        <div class="topbar">
            <div class="topbar-wrapper">
                <div class="user-box">
                    Welcome <%= customer != null ? customer.getFirstName() + " " + customer.getLastName() : "Guest"%>!
                    <% if (customer != null) {%>
                    <a href="/logout" onclick="return confirm('Are you sure you want to log out?')">(Log out)</a>
                    <% }%>
                </div>
                <div class="login-box">
                    <div class="login-area">
                        <% if (customer != null) {%>
                        <h4>Account Panel</h4>
                        <ul>
                            <li><a href="/">Home</a></li>
                            <% if (customer.getType().equals("admin")) {%>
                            <li><a href="/manage">Admin Area</a></li>
                            <% }%>
                            <li><a href="/account/profile">Profile</a></li>
                            <li><a href="/logout">Sign out</a></li>
                        </ul>
                        <% } else {%>
                        <p class="error"></p>
                        <form action="/login" method="post" class="register-form" name="login-form">
                            <table>
                                <tr>
                                    <td><input type="text" name="username" placeholder="Email Address" value=""/></td>
                                </tr>
                                <tr>
                                    <td><input type="password" name="password" placeholder="Password" value=""/></td>
                                </tr>
                                <tr>
                                    <td><input type="submit" value="Log in" name="login" /></td>
                                </tr>
                                <tr>
                                    <td><a href="/register">Create your account</a></td>
                                </tr>
                            </table>
                        </form>
                        <% }%>
                    </div>
                    <div class="login-btn">Account</div>
                </div>
                <div class="clear"></div>
            </div>
        </div>
        <div class="wrapper">

            <% if (request.getSession().getAttribute("message") != null) {%>
            <div class="message">
                <%= request.getSession().getAttribute("message")%>
            </div>
            <%
                    request.getSession().removeAttribute("message");
                }
            %>
            <% if (request.getSession().getAttribute("error") != null) {%>
            <div class="error">
                <%= request.getSession().getAttribute("error")%>
            </div>
            <%
                    request.getSession().removeAttribute("error");
                }
            %>